package com.servlet;

import com.DAO.GoodsDaoImpl;
import com.google.gson.Gson;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;


import java.io.IOException;

@WebServlet("/deleteGoods")
public class DeleteGoodsServlet extends HttpServlet {
    private GoodsDaoImpl goodsDaoImpl = new GoodsDaoImpl();
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("application/json;charset=UTF-8");

        try {
            int gid = Integer.parseInt(req.getParameter("gid"));
            boolean success = goodsDaoImpl.deleteGoods(gid);
            resp.getWriter().write(new Gson().toJson(success));
        } catch (Exception e) {
            e.printStackTrace();
            resp.getWriter().write(new Gson().toJson(false));
        }
    }
}